//-----------------------------------------------------------------------
//<copyright file="ChiTietBienBanKiemKeKhoDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class ChiTietBienBanKiemKeKhoDAO : SQLDatabase, IChiTietBienBanKiemKeKhoDAO
	{

        #region Create ChiTietBienBanKiemKeKho methods

        public ChiTietBienBanKiemKeKho CreateChiTietBienBanKiemKeKho(ChiTietBienBanKiemKeKho chiTietBienBanKiemKeKho)
        {
            try
            {

                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoInsert");
                AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, chiTietBienBanKiemKeKho.MaBBKKK);
                AddInParameter(command, "@MaLuuKho", SqlDbType.Int, chiTietBienBanKiemKeKho.MaLuuKho);
                AddInParameter(command, "@TonSoSach", SqlDbType.Int, chiTietBienBanKiemKeKho.TonSoSach);
                AddInParameter(command, "@TonThucTe", SqlDbType.Int, chiTietBienBanKiemKeKho.TonThucTe);
                AddInParameter(command, "@ChenhLechThucTe", SqlDbType.Int, chiTietBienBanKiemKeKho.ChenhLechThucTe);
                AddInParameter(command, "@TinhTrang", SqlDbType.NVarChar, chiTietBienBanKiemKeKho.TinhTrang);

                ExecuteNonQuery(command);
                return chiTietBienBanKiemKeKho;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access CreateChiTietBienBanKiemKeKhoException", ex);
            }
        }

        #endregion

        #region Update ChiTietBienBanKiemKeKho methods

        public void UpdateChiTietBienBanKiemKeKho(ChiTietBienBanKiemKeKho chiTietBienBanKiemKeKho)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoUpdate");

                AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, chiTietBienBanKiemKeKho.MaBBKKK);
                AddInParameter(command, "@MaLuuKho", SqlDbType.Int, chiTietBienBanKiemKeKho.MaLuuKho);
                AddInParameter(command, "@TonSoSach", SqlDbType.Int, chiTietBienBanKiemKeKho.TonSoSach);
                AddInParameter(command, "@TonThucTe", SqlDbType.Int, chiTietBienBanKiemKeKho.TonThucTe);
                AddInParameter(command, "@ChenhLechThucTe", SqlDbType.Int, chiTietBienBanKiemKeKho.ChenhLechThucTe);
                AddInParameter(command, "@TinhTrang", SqlDbType.NVarChar, chiTietBienBanKiemKeKho.TinhTrang);

                ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access UpdateChiTietBienBanKiemKeKhoException", ex);
            }
        }

        #endregion

		#region Delete ChiTietBienBanKiemKeKho methods

		public void DeleteChiTietBienBanKiemKeKho(ChiTietBienBanKiemKeKho chiTietBienBanKiemKeKho)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoDelete");

				AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, chiTietBienBanKiemKeKho.MaBBKKK);
                AddInParameter(command, "@MaLuuKho", SqlDbType.Int, chiTietBienBanKiemKeKho.MaLuuKho);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteChiTietBienBanKiemKeKhoException", ex);
			}
		}

        public void DeleteChiTietBienBanKiemKeKhoByMaBBKKK(string maBBKKK)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoDeleteAllByMaBBKKK");

                AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, maBBKKK);

                ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access DeleteChiTietBienBanKiemKeKhoException", ex);
            }
        }


		#endregion

		#region Select methods

		#region GetAll ChiTietBienBanKiemKeKho methods

		public ChiTietBienBanKiemKeKhos GetAllChiTietBienBanKiemKeKho()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoGetList");
				ChiTietBienBanKiemKeKhos Result = new ChiTietBienBanKiemKeKhos();
				List<ChiTietBienBanKiemKeKho> List = ExecuteQuery<ChiTietBienBanKiemKeKho>(command,true);
				foreach(ChiTietBienBanKiemKeKho item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllChiTietBienBanKiemKeKhoException", ex);
			}
		}

        public ChiTietBienBanKiemKeKhos GetAllChiTietBienBanKiemKeKhoByMaBBKK(string maBBKK)
        {
            try
            {

                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoSelectAllByMaBBKKK");
                AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, maBBKK);
                ChiTietBienBanKiemKeKhos Result = new ChiTietBienBanKiemKeKhos();
                List<ChiTietBienBanKiemKeKho> List = ExecuteQuery<ChiTietBienBanKiemKeKho>(command, true);
                foreach (ChiTietBienBanKiemKeKho item in List)
                {
                    Result.Add(item);
                }
                return Result;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access GetAllChiTietBienBanKiemKeKhoException", ex);
            }
        }


		#endregion


		#region GetChiTietBienBanKiemKeKho methods

        public ChiTietBienBanKiemKeKho GetChiTietBienBanKiemKeKhoByID(string maBBKKK, int maLuuKho)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoGet");

				AddInParameter(command, "@maBBKKK", SqlDbType.NVarChar, maBBKKK);
                AddInParameter(command, "@MaLuuKho", SqlDbType.Int, maLuuKho);
				return ExecuteQuery<ChiTietBienBanKiemKeKho>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetChiTietBienBanKiemKeKhoBy ID Exception", ex);
			}
		}

        public ChiTietBienBanKiemKeKhos GetChiTietBienBanKiemKeKhoByMonthAndYear(int month, int year)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoGetByMonthAndYear");

                AddInParameter(command, "@month", SqlDbType.Int, month);
                AddInParameter(command, "@year", SqlDbType.Int, year);
                ChiTietBienBanKiemKeKhos Result = new ChiTietBienBanKiemKeKhos();
                List<ChiTietBienBanKiemKeKho> List = ExecuteQuery<ChiTietBienBanKiemKeKho>(command, true);
                foreach (ChiTietBienBanKiemKeKho item in List)
                {
                    Result.Add(item);
                }
                return Result;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access GetChiTietBienBanKiemKeKhoBy ID Exception", ex);
            }
        }

        public ChiTietBienBanKiemKeKhos GetChiTietBienBanKiemKeKhoByMaKy(string maky)
        {
            try
            {
                //SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoGetByMaKy");
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanKiemKeKhoGetByMaKy_ChuaDongKy"); //Get TonKho value from tbl_LuuKho
                AddInParameter(command, "@maKy", SqlDbType.NVarChar, maky);
                
                ChiTietBienBanKiemKeKhos Result = new ChiTietBienBanKiemKeKhos();
                List<ChiTietBienBanKiemKeKho> List = ExecuteQuery<ChiTietBienBanKiemKeKho>(command, true);
                foreach (ChiTietBienBanKiemKeKho item in List)
                {
                    Result.Add(item);
                }
                return Result;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access GetChiTietBienBanKiemKeKhoBy ID Exception", ex);
            }
        }

		#endregion


		#endregion
	}
}//End Class
